const baseURL = 'https://test.cvbloc.com'

function request(url, method, data) {
	return new Promise((resolve, reject) => {
		let token = uni.getStorageSync('userTokenStr')
		uni.request({
			url: baseURL + url,
			method,
			data,
			header: {
				"Token": token,
				// "content-type": 'application/x-www-form-urlencoded'
			},
			success:(res) => {
				// 这儿还要根据请求回来的数据做判断来确定是否抛出
				if(res.statusCode === 500) {
					uni.showToast({
						icon: 'none',
						title: '请求失败'
					})
					reject(res)
				}else {
					resolve(res)
				}
			},
			fail: (err) => {
				uni.showToast({
					icon: 'none',
					title: '请求失败'
				})
				reject(err)
			}	
		})
	})
}

export default request